package com.laborer.PTSS.service.impl;

import com.laborer.PTSS.domain.Course;
import com.laborer.PTSS.service.SearchService;
import com.laborer.PTSS.util.JDBCUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class SearchServiceImpl implements SearchService {
    private JdbcTemplate template = new JdbcTemplate(JDBCUtils.getDataSource());
    @Override
    public List<Course> getCourseListBySearch(String name) {
        String sql = "select * from tab_course where title LIKE '%" + name + "%'" +
        "OR uid like '%"+ name + "%' or description like '%"+ name +"%' order by price asc";
        //System.out.println(sql);
        return template.query(sql, new BeanPropertyRowMapper<Course>(Course.class));
    }
}
